package org.millioncall.yueyoga.admin.dao.impl;

import java.util.List;
import java.util.Map;

import org.millioncall.openplatform.common.PaginateParams;
import org.millioncall.openplatform.common.PaginatedList;
import org.millioncall.openplatform.common.StartLimitPairImpl;
import org.millioncall.openplatform.dao.PreparedQuery;
import org.millioncall.yueyoga.admin.dao.BaseDao;
import org.millioncall.yueyoga.admin.dao.ResourceDAO;
import org.millioncall.yueyoga.admin.model.Resource;

/**
 * 资源DAO实现类
 * 
 * @author zangjinyu
 * @version 1.0.0
 * @since 2014-3-28
 * 
 */
public class ResourceDAOImpl extends BaseDao implements ResourceDAO {

	@Override
	public List<Resource> findResourceByAuthorityId(Integer authorityId) {
		return this.getPagableSqlSessionTemplate().selectList(
				"findResourceByAuthorityId", authorityId);
	}

	@Override
	public PaginatedList<Resource> findAllResources(int start, int limit,
			Map<String, String> map) {
		PreparedQuery<Resource> pq = this.getPagableSqlSessionTemplate()
				.findAll("findAllResources", map);
		PaginatedList<Resource> pl = pq.list(new PaginateParams(
				new StartLimitPairImpl(start, limit)));
		return pl;
	}

	@Override
	public int deleteResources(List<Integer> rIds) {
		return this.getPagableSqlSessionTemplate().delete("deleteResources",
				rIds);
	}

	@Override
	public int saveResource(Resource resource) {
		return this.getPagableSqlSessionTemplate().insert("saveResource",
				resource);
	}

	@Override
	public int updateResource(Resource resource) {
		return this.getPagableSqlSessionTemplate().update("saveResource",
				resource);
	}

	@Override
	public List<Resource> findResources(boolean b) {
		return this.getPagableSqlSessionTemplate().selectList("findResources",
				b == true ? "1" : "2");
	}

	@Override
	public Resource findResourceByName(String name) {
		return this.getPagableSqlSessionTemplate().selectOne("findResourceByName", name);
	}
}
